#####################################################################
# Product:      KnowledgeEngine (Plone Edition)
#
# File:         PermissionDefinition.py
#
# Copyright:    Copyright (c) 2004, Faulkner Technologies
#
# Author:       Brian Oliver
#
# Description:  A PermissionDefinition is an object that represents
#               runtime information pertaining to the
#               available Knowledge Engine permissions
#
# See Also:     SecurityService, ClassInfo
#####################################################################

#####################################################################
## KnowledgeEngine Library Imports
from Common import *

#####################################################################
## Zope Library Imports
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
 
#####################################################################
## Python Library Imports
# (none)

#The securable scopes (what types of securables are permitted)
SS_SPECIFIC = "SPECIFIC"
SS_GENERIC = "GENERIC"
SS_ALL = "ALL"

#The actor scopes (what types of actors are permitted)
AS_USERS = "USERS"
AS_GROUPS = "GROUPS"
AS_ALL = "ALL"

#####################################################################
## PermissionDefinition Class Definition
class PermissionDefinition(RoleManager):
    """
        Instances of this class define individual permission information
        (generally for classes of GenericObject)
    """

    #---------------------------------------------------------------#

    #define security
    security = ClassSecurityInfo()
    security.declareObjectPublic()
    security.setDefaultAccess("allow")

    #---------------------------------------------------------------#

    def __init__(self, identity, displayName, description="", securableScope=SS_ALL, actorScope=AS_ALL, usesCredits=false, isCommencementPermitted=true, isExpiryPermitted=true, usesAssessmentScope=false):
        """
            Defines the state of a Permisison Definition.
            
            PARAMETERS:
            
            identity:                   The unique identity for the permission for a single class (of GenericObject)
    
            displayName:                The name used to display the permission (typically in the user-interface)
            
            description:                The description/purpose of the permission
            
            securableScope:             The types of securables that the permission may use (specific, generic or all)
            
            actorScope:                 The types of actors that the permission may use (users, groups, all)
            
            usesCredits:                If the permission requires the use of credits.
            
            isCommencementPermitted:    If the permission permits the use of date of commencment
            
            isExpiryPermitted:          If the permission permits the use of date of expiry

            usesAssessmentScope:        If the permission requires an assessment scope (a list of actorIdentities) [String]
        """        
        
        self.identity = identity
        self.displayName = displayName
        self.description = description
        self.securableScope = securableScope
        self.actorScope = actorScope
        self.usesCredits = usesCredits
        self.isCommencementPermitted = isCommencementPermitted
        self.isExpiryPermitted = isExpiryPermitted
        self.usesAssessmentScope = usesAssessmentScope
        
    #---------------------------------------------------------------#

    def getIdentity(self):
        """
            Returns the unique identity for the property, which is 
            used to identify the property in an object
            
            RETURN TYPE: String
        """
        
        return self.identity

    #---------------------------------------------------------------#

    def getDisplayName(self):
        """
            Returns the string name for the property used to display
            and construct property editors
            RETURN TYPE: String
        """
        
        return self.displayName

    #---------------------------------------------------------------#

    def setDisplayName(self, displayName):
        """
            Sets the string name for the property used to display
            and construct property editors
        """
        
        self.displayName = displayName

    #---------------------------------------------------------------#

    def getDescription(self):
        """
            Returns the string description for the property.  Used to 
            display construct property editors
            RETURN TYPE: String
        """
        
        return self.description

    #---------------------------------------------------------------#

    def setDescription(self, description):
        """
            Sets the string description for the property.  Used to 
            display construct property editors
            RETURN TYPE: String
        """
        
        self.description = description
        
    #---------------------------------------------------------------#

    def getUsesCredits(self):
        """
            Returns if the permission uses credits
            
            RETURN TYPE: Boolean
        """            
        
        return self.usesCredits
        
    #---------------------------------------------------------------#

    def getUsesAssessmentScope(self):
        """
            Returns if the permission uses assessment scope
            
            RETURN TYPE: Boolean
        """            
        
        return self.usesAssessmentScope
        
    #---------------------------------------------------------------#

#####################################################################
## Class Initialisation
InitializeClass(PermissionDefinition)
